class ListNode {
  constructor(value = 0, next = null) {
      this.value = value;
      this.next = next;
  }
}

class LinkedList {
  constructor() {
      this.head = null; // 链表的头节点
  }

  // 添加节点到链表末尾
  append(value) {
      if (!this.head) {
          this.head = new ListNode(value);
          return;
      }
      let current = this.head;
      while (current.next) {
          current = current.next;
      }
      current.next = new ListNode(value);
  }

  // 打印链表的所有值
  print() {
      let current = this.head;
      while (current) {
          console.log(current.value);
          current = current.next;
      }
  }
}

const list = new LinkedList();
list.append(1);
list.append(2);
list.append(3);
list.print(); // 输出: 1, 2, 3